<template>
	<view>
		<view class="p-3">
			<u-list v-if="dataList.length>0" @scrolltolower="loadMore" style="height:calc(100vh - 360rpx)">
				<borrow-item v-for="i, idx in dataList" :item="i" :key="idx" @click="gotoDoc(i)"></borrow-item>
			</u-list>
			<u-empty v-else></u-empty>
		</view>
		<view class="bt-footer">
			<view class="w-100 text-center">
				<view class="font-12 text-grey1 mb-3">共计 {{total}} 条</view>
				<bg-btn style="background-color: #ffefe7;color:#EE3636;">
					共计待发金额：{{totalAmount}}元
				</bg-btn>
			</view>
		</view>
	</view>
</template>

<script>
	import { tobeSend, tobeSendTotal } from '../../../api/salary'
	import borrowItem from './components/borrow-item.vue'
	export default {
		components:{borrowItem},
		data() {
			return {
				dataList:[],
				total:'',
				totalAmount:0,
				params:{
					pageNum:1,
					pageSize:10,
				}
			}
		},
		mounted() {
			this.getData()
			uni.$on("refresh-borrow", ()=>{
				this.params.pageNum = 1
				this.dataList = []
				this.getData()
			})
		},
		methods: {
			loadMore(){
				if(this.dataList.length<this.total){
					this.params.pageNum+=1
					this.getData()
				}
			},
			getData(){
				
				tobeSend().then(res=>{
					this.dataList = [...this.dataList, ...res.data.rows]
					this.total = res.data.total
				})
				tobeSendTotal().then(res=>{
					this.totalAmount = res.data
				})
			},
			gotoDoc(i){
				uni.navigateTo({
					url:"/pages/project/grant/borrow-doc?show=1&bid="+i.id
				})
			}
		}
	}
</script>

<style>

</style>
